# _*_ coding: utf-8 _*_
__author__ = 'yinlei'
__date__ = '2018-05-26 15:51'

from exts import db
from apps.bases.base_mode import BaseMode
from sqlalchemy.dialects.mysql import LONGTEXT
from sqlalchemy import Column


class Banner(BaseMode):
    __tablename__ = 'banner'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(50), nullable=False, unique=True)
    image_url = db.Column(db.String(255), nullable=False)
    link_url = db.Column(db.String(255), nullable=False)
    priority = db.Column(db.Integer, default=0)


class BoardModel(BaseMode):
    __tablename__ = 'board'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    name = db.Column(db.String(20), nullable=False)
    posts = db.relationship('PostModel',back_populates='board')


class PostModel(BaseMode):
    __tablename__ = 'post'
    id = db.Column(db.Integer,primary_key=True,autoincrement=True)
    title = db.Column(db.String(200),nullable=False)
    content = db.Column(db.Text,nullable=False)
    big_content = Column(LONGTEXT,nullable=False,default='')
    board_id = db.Column(db.Integer,db.ForeignKey('board.id'))
    board = db.relationship('BoardModel',back_populates='posts')
    author_id = db.Column(db.String(100),db.ForeignKey('front_user.id'))
    author = db.relationship('FrontUser',back_populates='posts')

    comments = db.relationship('CommentModel',back_populates='post')
    highlight = db.relationship('HighlightPostModel',back_populates='post',uselist=False)
class HighlightPostModel(BaseMode):
    __tablename__ ='heighlight_post'
    id = db.Column(db.Integer,primary_key=True,autoincrement=True)
    post_id = db.Column(db.Integer,db.ForeignKey('post.id'))
    post = db.relationship('PostModel',back_populates='highlight')

class CommentModel(BaseMode):
    __tablename__ = 'comment'
    id = db.Column(db.Integer,primary_key=True,autoincrement=True)
    content = db.Column(db.Text,nullable=False)

    post_id = db.Column(db.Integer,db.ForeignKey('post.id'))
    post = db.relationship('PostModel',back_populates='comments')

    author_id =  db.Column(db.String(200),db.ForeignKey('front_user.id'))
    author = db.relationship('FrontUser',back_populates='comments')